package com.device.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.device.Entity.User;
import com.device.Service.UserService;
import com.device.annotation.GlobalInterceptor;
import com.device.common.PageResult;
import com.device.common.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping("/add")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result add(User user){
        userService.adduser(user);
        return Result.success();
    }
    @RequestMapping("/list")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result list(Integer pageNo,Integer pageSize,String keyword){
       PageResult pageResult=userService.getpage(pageNo,pageSize,keyword);
       return Result.success(pageResult);
    }
    @RequestMapping("/userlist")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result userlist(Integer pageNo,Integer pageSize,String keyword){
        PageResult pageResult=userService.getuserpage(pageNo,pageSize,keyword);
        return Result.success(pageResult);
    }
    @RequestMapping("/edit")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result edit(User user){
        userService.edituser(user);
        return Result.success();
    }
    @RequestMapping("/delete")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result delete(Integer id){
        userService.del(id);
        return Result.success();
    }
    @RequestMapping("/labuser")
    @GlobalInterceptor(checkParam = true,checkLogin = true)
    public Result labuser(){
        List<Map<String,Object>> list=userService.getlabuser();
        return Result.success(list);
    }




}
